<?php
/**
 * Filename: 05-ChocolateBoiler.php
 * Head First 设计模式 第5章 巧克力工厂锅炉
 */

/**
 * 巧克力锅炉单件类
 *
 */
class ChocolateBoiler {
	/**
	 * 锅炉是否为空
	 *
	 * @var boolean
	 */
	private $empty;
	private $boiled;
	
	/**
	 * 保存对象实例
	 * 
	 * @var ChocolateBoiler
	 */
	private static $instance = NULL;
	
	/**
	 * 初始化巧克力锅炉 空的 没有熟
	 *
	 */
	private  function __construct() {
		$this->empty = true;
		$this->boiled = false;
	} //END func __construct
	
	/**
	 * 私有的构造和析构函数
	 *
	 */
	public function __destruct() {
		
	} //END func __destrauct
	
	/**
	 * 静态共有方法，返回类对象
	 *
	 * @return ChocolateBoiler
	 */
	public static function getInstance() {
		if (self::$instance == null) {
			echo "new ChocolateBoiler.<br />";
			self::$instance = new ChocolateBoiler();
		} 
		return self::$instance;
	} //END func getInstance
	
	/**
	 * 私有克隆函数，禁止克隆
	 */
	private function __clone() {
		trigger_error("Can't be Cloned.", E_USER_ERROR);   
	} //END func __clone
	
	/**
	 * 判断是否为空
	 *
	 * return boolean
	 */
	public function isEmpty() {
		return $this->empty;		
	} //END func isEmpty
	
	/**
	 * 判断锅炉是否熟了
	 * 
	 * return boolean
	 */
	public function isBoiled() {
		return $this->boiled;
	} //END func isBoiled
	
	/**
	 * 填充锅炉
	 *
	 */
	public function fill() {
		if ($this->isEmpty()) {
			$this->empty = false;
			$this->boiled = false;
			//在锅炉中填满巧克力和牛奶的混合物
		}
	} //END func fill 
	
	/**
	 * 排尽锅炉
	 *
	 */
	public function drain() {
		if (!$this->isEmpty() && $this->isBoiled()) {
			$this->empty = true;
		}
	} //END func drain
	
	public function boiled() {
		if (!$this->isEmpty() && !$this->isBoiled()) {
			//将锅内物煮熟
			$this->boiled = true;
		}
	} //END func boiled
	

	
} //END class ChocolateBoiler
?>


<?php
//$test1 = new ChocolateBoiler();
$test1 = ChocolateBoiler::getInstance();
//$test1_clone = clone $test1;
?>